package day0314

func majorityElement(nums []int) int {
	candidate, count := 0, 0
	for num := range nums {
		if count == 0 {

			candidate = num
		}
		if num == candidate {
			count++
		} else {
			count--
		}
	}
	return candidate
}
